/**
 * @file Macros.h
 * @brief Macros and typedefs for GDR programmers (some of the macros
 *         are advertised as functions)
 * @author Matt Stallmann @date 18 Dec 2001
 * $Id: Macros.h 11 2007-06-28 20:13:46Z mfms $
 */

/*
 *  Copyright (C) 1989, 2001, 2007  Matthias Stallmann, Prashant Hebbar.
 *  Contact: matt_stallmann@ncsu.edu
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program (file COPYING.txt); if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
 *  USA.
 */

#ifndef MACROS_H
#define MACROS_H

/* Boolean constants */
#define	TRUE	1
#define	FALSE	0

/* edge and vertex types and constants */
typedef int	vertex;
typedef struct list_node * edge;
#define NULL_EDGE	NULL
#define NULL_VERTEX (-1)
#ifndef MAX_VERTEX
/** The maximum number of vertices allowed (currently, if MAX_VERTEX > 100,
    only the last two digits of id's will be printed) */
#define MAX_VERTEX 100
/** Maximum length of the string representing a vertex number (not
    universally used yet) */
#define MAX_VERTEX_STRING_LENGTH 2
#endif

/* macros for more convenient access to data and functions */
#define first_in_edge(vx)	first_in_out_edge(vx,TRUE)
#define first_out_edge(vx)	first_in_out_edge(vx,FALSE)

#define next_in_edge(vx,edj)	next_in_out_edge(vx,edj,TRUE)
#define next_out_edge(vx,edj)	next_in_out_edge(vx,edj,FALSE)

#define knot_0_x(ej)		knot(ej,0,0)
#define knot_0_y(ej)		knot(ej,0,1)
#define knot_1_x(ej)		knot(ej,1,0)
#define knot_1_y(ej)		knot(ej,1,1)

#define edge_label_x(e)        LX(e)
#define edge_label_y(e)        LY(e)

#define move_knot_0(ej,del_x,del_y)	mov_knot(ej,0,del_x,del_y)
#define move_knot_1(ej,del_x,del_y)	mov_knot(ej,1,del_x,del_y)

#define window_width()		window_width_height(TRUE)
#define window_height()		window_width_height(FALSE)

/* macros for graph traversal */

/**    traversing the adjacency list of a vertex: */
#define for_adjacent(v,e,w) for (e = first_out_edge(v);\
     e != NULL_EDGE ? (w = other_vertex(v,e), TRUE) : FALSE;\
     e = next_out_edge(v,e))

/**    traversing the incoming adjacency list of a vertex: */
#define for_incoming_edges(v,e,u) for (e = first_in_edge(v);\
     e != NULL_EDGE ? (u = other_vertex(v,e), TRUE) : FALSE;\
     e = next_in_edge(v,e))

/**    accessing all valid vertices */
#define for_all_vertices(v) for(v = 0; v <= max_vertex(); v++)\
                              if (is_valid_vertex(v))

/**    accessing all edges */
#define for_all_edges(e) for (e = first_edge(); e != NULL_EDGE;\
                              e = next_edge(e))

/* miscellaneous macros */
#define BEEP /**/

/* audio_bell(5) */

#endif
/** end of Macros.h **/

/*  [Last modified: 2007 06 28 at 20:12:01 GMT] */
